<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="common/include :: header('客户列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <div class="select-list">
                    <ul>
                        <li>
                            关键字：<input type="text" placeholder="企业名称/法定代表人/所属行业" name="Keyword"/>
                        </li>
                        <li>
                            经营状态：
                            <select name="openState" th:with="type=${@dict.getType('bus_open_state')}">
                                <option value="">请选择</option>
                                <option th:each="dict : ${type}" th:text="${dict.label}"
                                        th:value="${dict.value}"></option>
                            </select>
                        </li>
                        <li>
                            所属地区：
                            <select name="province" th:with="type=${@dict.getType('bus_province')}">
                                <option value="">请选择</option>
                                <option th:each="dict : ${type}" th:text="${dict.label}"
                                        th:value="${dict.value}"></option>
                            </select>
                        </li>
                        <li>
                            开始时间：<input type="text" class="arrivalTime" placeholder="开始时间" name="startTime"/>
                        </li>
                        <li>
                            结束时间：<input type="text" class="arrivalTime" placeholder="结束时间" name="endTime"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:post:add">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-warning" onclick="$.operate.edit()" id="edit" shiro:hasPermission="system:post:edit">
                <i class="fa fa-plus"></i> 修改
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="common/include :: footer"/>
<th:block th:include="common/include :: datetimepicker" />

<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:post:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:post:remove')}]];
    var datas = [[${@dict.getType('sys_normal_disable')}]];
    var openStateDatas = [[${@dict.getType('bus_open_state')}]];
    var provinceDatas = [[${@dict.getType('bus_province')}]];
    var prefix = ctx + "/business/customer";
    $(function () {
        var options = {
            url: prefix + "/query",
            createUrl: prefix + "/addPage",
            updateUrl: prefix + "/editPage?id={id}",
            removeUrl: prefix + "/remove",
            modalName: "客户信息",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '序号',
                    visible: true
                },
                {
                    field: 'customerName',
                    title: '企业名称',
                    sortable: true
                },

                {
                    field: 'legalLeader',
                    title: '法定代表人',
                    sortable: true
                },
                {
                    field: 'registerDate',
                    title: '成立日期',
                    sortable: true
                },
                {
                    field: 'industry',
                    title: '所属行业',
                    sortable: true
                },
                {
                    field: 'province',
                    title: '所属地区',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(provinceDatas, value);
                    }
                },
                {
                    field: 'openState',
                    title: '经营状态',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(openStateDatas, value);
                    }
                },
                {
                    field: 'user.userName',
                    title: '录入人',
                    sortable: true
                },
                {
                    field: 'user.userName',
                    title: '营销人',
                    sortable: true
                },
                {
                    field: 'inputTime',
                    title: '录入时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs id="edit" '  + editFlag + '" href="javascript:void(0)" ' +
                            'onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');

                        actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)"  ' +
                            'onclick="saleOn(\'' + row.id + '\')"><i class="fa fa-edit"></i>详情</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    $('#bootstrap-table').on('uncheck-all.bs.table check-all.bs.table uncheck.bs.table check.bs.table load-success.bs.table', function () {
        $('#edit').addClass("disabled");

        var rows = $('#bootstrap-table').bootstrapTable('getSelections');

        // 如果不是选中1行
        if (rows.length !== 1) {
            return;
        }

        $('#edit').removeClass("disabled");
    });

    // 时间控件
    $('.arrivalTime').datetimepicker({
        format:'yyyy-mm-dd hh:ii',
        autoclose:true
    });
</script>
</body>
</html>